package org.example.covid.entity;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CovidCountEntity implements WritableComparable<CovidCountEntity> {
    private long cases;
    private long deaths;

    public CovidCountEntity() {
    }

    public CovidCountEntity(long cases, long death) {
        this.cases = cases;
        this.deaths = death;
    }

    public void set(long cases, long death) {
        this.cases = cases;
        this.deaths = death;
    }

    public long getCases() {
        return cases;
    }

    public void setCases(long cases) {
        this.cases = cases;
    }

    public long getDeaths() {
        return deaths;
    }

    public void setDeaths(long deaths) {
        this.deaths = deaths;
    }

    @Override
    public String toString() {
        return cases + "\t" + deaths;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(cases);
        out.writeLong(deaths);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.cases = in.readLong();
        this.deaths = in.readLong();
    }

    /**
     * 正序
     * a1.compareTo(a2)
     * a1 > a2,  1
     * a1 == a2, 0
     * a1 < a2,  -1
     * 倒序
     * a1.compareTo(a2)
     * a1 > a2,  -1     a1排在前面
     * a1 == a2, 0
     * a1 < a2,  1      a1排在后面
     * @param o
     * @return
     */
    @Override
    public int compareTo(CovidCountEntity o) {
        return this.cases > o.cases? -1: (this.cases < o.cases? 1: 0);
    }
}
